package com.hs.communication.common.fallback;

import com.hs.common.core.domain.Result;
import com.hs.communication.common.entity.UpsData;
import com.hs.communication.common.entity.vo.DeviceVo;
import com.hs.communication.common.feign.RemoteUpsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class RemoteUpsFallbackFactory implements FallbackFactory<RemoteUpsService> {

    @Override
    public RemoteUpsService create(Throwable cause) {
        log.error("ups实时信息插入服务调用失败:{}", cause.getMessage());
        return new RemoteUpsService() {
            @Override
            public Result<DeviceVo> getStatistics(String source) {
                System.out.println("ups统计降级回调");
                return Result.fail(DeviceVo.builder().build());
            }

            @Override
            public void insert(UpsData upsData, String source) {

            }
        };
    }
}
